package sw6.app2;

import java.util.ArrayList;

import sw6.lib.internal.debug.*;
import sw6.lib.Settings;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

/**
 * Tests install of sw6.app2v1
 * @author sw6b
 */
public class TestActivity extends Activity {
	
	private static final String APP_NAME 	= "sw6.app2v1";
	private int testNumber 					= 0;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		//Define the resulting intent
		Intent resultIntent 		= new Intent();
		ArrayList<Boolean> results 	= new ArrayList<Boolean>();
		
		// TEST NO. 0
		try {
			boolean value 		= Settings.getBoolean(this, "boolean1");
			boolean expected	= true;
			if(value == expected) {
				DebugHelpers.logPass(testNumber, APP_NAME);
				results.add(true);
			} else {
				throw new Exception("Expected: " + expected + ", was: " + value);
			}
		} catch(Exception e) {
			DebugHelpers.logIssue(testNumber, APP_NAME, e.getMessage());
			results.add(false);
		}
		testNumber++;
		
		// TEST NO. 1
		try {
			double value 		= Settings.getDouble(this, "double1");
			double expected		= 1.0;
			if(value == expected) {
				DebugHelpers.logPass(testNumber, APP_NAME);
				results.add(true);
			} else {
				throw new Exception("Expected: " + expected + ", was: " + value);
			}
		} catch(Exception e) {
			DebugHelpers.logIssue(testNumber, APP_NAME, e.getMessage());
			results.add(false);
		}
		testNumber++;
		
		// TEST NO. 2
		try {
			int value 		= Settings.getInteger(this, "int1");
			int expected	= 11;
			if(value == expected) {
				DebugHelpers.logPass(testNumber, APP_NAME);
				results.add(true);
			} else {
				throw new Exception("Expected: " + expected + ", was: " + value);
			}
		} catch(Exception e) {
			DebugHelpers.logIssue(testNumber, APP_NAME, e.getMessage());
			results.add(false);
		}
		testNumber++;

		// TEST NO. 3
		try {
			String value 	= Settings.getString(this, "string1");
			String expected	= "sw6b";
			if(value.equals(expected)) {
				DebugHelpers.logPass(testNumber, APP_NAME);
				results.add(true);
			} else {
				throw new Exception("Expected: \"" + expected + "\", was: \"" + value + "\"");
			}
		} catch(Exception e) {
			DebugHelpers.logIssue(testNumber, APP_NAME, e.getMessage());
			results.add(false);
		}
		testNumber++;
		
		// TEST NO. 4
		try {
			int value 		= Settings.getEnum(this, "enum1");
			int expected	= 1;
			if(value == expected) {
				DebugHelpers.logPass(testNumber, APP_NAME);
				results.add(true);
			} else {
				throw new Exception("Expected: " + expected + ", was: " + value);
			}
		} catch(Exception e) {
			DebugHelpers.logIssue(testNumber, APP_NAME, e.getMessage());
			results.add(false);
		}
		testNumber++;
		
		// TEST NO. 5
		try {
			Integer value 		= Settings.getObject(this, "object1", Integer.class);
			Integer expected	= null;
			if(value == expected) {
				DebugHelpers.logPass(testNumber, APP_NAME);
				results.add(true);
			} else {
				throw new Exception("Expected: " + expected + ", was: " + value);
			}
		} catch(Exception e) {
			DebugHelpers.logIssue(testNumber, APP_NAME, e.getMessage());
			results.add(false);
		}
		
		resultIntent.putExtra("appName", this.getString(R.string.app_name));
		resultIntent.putExtra("results", DebugHelpers.getBooleanArray(results));
		setResult(RESULT_OK, resultIntent);
		finish();
	}
}
